

package com.example.administrator.caigou51.recyclerCard.cardView;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.caigou51.EventBusClass.CheckOrderSetValue;
import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.activity.GBaseActivity;
import com.example.administrator.caigou51.activity.StoreManagerActivity;
import com.example.administrator.caigou51.activity.ZhiZhiCheckActivity;
import com.example.administrator.caigou51.recyclerCard.basic.CardItemView;
import com.example.administrator.caigou51.recyclerCard.card.StoreManagerCard;
import com.example.administrator.caigou51.util.ToastUtil;

import java.io.Serializable;

import de.greenrobot.event.EventBus;


public class StoreManagerCardView extends CardItemView<StoreManagerCard> {
 	private Context mContext;
    private StoreManagerCard card;
    private TextView textViewName;
    private TextView textViewState;
    private TextView textView_add;
    public static String stateShenKeIng="0";
    public static  String stateRenZheng="1";
    public static  String stateShenKeFail="2";
    //0审核中1已认证 2审核失败
    public StoreManagerCardView(Context context) {
        super(context);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public StoreManagerCardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public StoreManagerCardView(Context context,
                                    AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext=context;
        // TODO Auto-generated constructor stub
    }
    @Override
    public void build(final StoreManagerCard card) {
        // TODO Auto-generated method stub
        super.build(card);
        this.card=card;
        textViewName = (TextView) findViewById(R.id.textViewName);
        textViewState = (TextView) findViewById(R.id.textViewState);
        textView_add = (TextView) findViewById(R.id.textView_add);

        if (card.getAddressEntity().getRegion_name()==null) {
            textView_add.setText(card.getAddressEntity().getAreaname() + card.getAddressEntity().getAddress());
        }else
        {
            textView_add.setText(card.getAddressEntity().getRegion_name() + card.getAddressEntity().getAddress());
        }
        textViewName.setText(card.getAddressEntity().getCompany_name());

        if (card.getAddressEntity().getIs_verified().equals(stateShenKeIng))
        {
            textViewState.setText("审核中");
        }else if  (card.getAddressEntity().getIs_verified().equals(stateRenZheng))
        {
            textViewState.setText("已认证");
        }else if  (card.getAddressEntity().getIs_verified().equals(stateShenKeFail))
        {
            textViewState.setText("审核失败");
        }

        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (StoreManagerActivity.isFromCheck) {
                    if  (card.getAddressEntity().getIs_verified().equals(stateRenZheng)) {
                        CheckOrderSetValue checkOrderSetValue = new CheckOrderSetValue();
                        checkOrderSetValue.setAddressEntity(card.getAddressEntity());
                        EventBus.getDefault().post(checkOrderSetValue);
                        ((GBaseActivity) mContext).finish();
                    }else
                    {
                        ToastUtil.showToast("只能选择已认证的店铺");
                    }
                }/*else if(StoreManagerActivity.isFromUserCenter) {
                    Intent intent=new Intent(mContext, ZhiZhiCheckActivity.class);
                    intent.putExtra(ZhiZhiCheckActivity.TagAddressEntity, (Serializable) card.getAddressEntity());
                    ((GBaseActivity) mContext).startActivity(intent);
                }*/
                else {
                    Intent intent = new Intent(mContext, ZhiZhiCheckActivity.class);
                    intent.putExtra(ZhiZhiCheckActivity.TagAddressEntity, (Serializable) card.getAddressEntity());
                    ((GBaseActivity) mContext).startActivity(intent);
                }
            }
        });
    }
}
